package com.zhdl.network.common_client;

import cn.hutool.core.util.HexUtil;
import com.project.command.faq.analysis.ComAnalysis;
import com.project.command.faq.analysis.ComAnalysisData;
import com.project.command.faq.analysis.ComAnalysisResult;
import com.zhdl.network.other_protocol.modbustcp.dto.ModbusResp;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service(CommonTcpClientAnalysis.COMMON_TCP_ANALYSIS)
public class CommonTcpClientAnalysis implements ComAnalysis<ModbusResp<Short>, List<ModbusResp<Short>>> {

    public static final String COMMON_TCP_ANALYSIS = "mod-bus";

    @Override
    public ComAnalysisResult<ModbusResp<Short>> analysisData(ComAnalysisData<List<ModbusResp<Short>>> data) {
        return new ComAnalysisResult<>(data.getBuf());
    }

    /**
     * 获取协议头信息
     */
    @Override
    public String getHeadAnalysis() {
        return "";
    }

    /**
     * 协议追加校验位信息（尾部数据）
     */
    @Override
    public byte[] getAfterAnalysis(String cmdStr) {
        return HexUtil.decodeHex(cmdStr);
    }
}
